<template>
    <div class="sub-layout org-content">
        <div class="sub-sidebar">
            <div class="search-bar">
                <div class="search-box">
                    <el-select v-model="search.value" placeholder="搜索用户..." filterable remote :remote-method="searchMethod" :loading="search.loading"
                        @change="searchChange">
                        <el-option v-for="item in search.list" :key="item.id" :label="item.userName" :value="item"></el-option>
                    </el-select>
                    <i class="icon i-search"></i>
                </div>
                <permission class="add" permission-key="salesDept:addSalesDept">
                    <a @click="showEditLayer(0)">
                        <i class="icon i-plus"></i>
                    </a>
                </permission>
            </div>
            <div class="side-nav">
                <tree-view :model="treeData" @on-selected="treeSelected" @on-toggle-expand="getOrgLevel"></tree-view>
            </div>
        </div>
        <div class="sub-main">
            <div class="content" v-if="currentData.name">
                <div class="section-info">
                    <span class="name">{{currentData.name}}</span>
                    <!-- <template v-if="currentData.sourceType==1"> -->
                    <template>
                        <permission permission-key="salesDept:editSalesDept">
                            <button @click="showEditLayer(1)">修改</button>
                        </permission>
                        <permission permission-key="salesDept:delSalesDept">
                            <button class="btn-delete" @click="showDeleteLayer(0)">删除</button>
                        </permission>
                        <permission permission-key="salesDept:addSalesDept">
                            <button @click="showEditLayer(2)">添加子部门</button>
                        </permission>
                    </template>
                </div>
                <div class="section section-table">
                    <div class="panel-title">
                        <span class="title">人员列表</span>
                        <!-- <div class="title-right" v-if="currentData.sourceType!=2"> -->
                        <div class="title-right">
                            <!-- <permission permission-key="orgUser:addOrgUser" v-if="currentData.sourceType==1"> -->
                            <permission permission-key="orgUser:addOrgUser">
                                <router-link :to="{path: '/system/org/edit', query: {code: currentData.deptCode}}">
                                    <button>添加人员</button>
                                </router-link>
                            </permission>
                        </div>
                    </div>
                    <div class="panel-content">
                        <el-table :data="tableData.data" border>
                            <el-table-column label="人员姓名" width="100">
                                <template slot-scope="scope">
                                    <router-link :to="{path: '/system/org/detail', query: {userid: scope.row.id,code: currentData.deptCode,source:currentData.sourceType || 1}}">{{scope.row.userName}}</router-link>
                                </template>
                            </el-table-column>
                            <el-table-column prop="email" label="邮箱地址" width="200">
                            </el-table-column>
                            <el-table-column prop="position" label="职位">
                            </el-table-column>
                            <el-table-column prop="identity" label="身份证号">
                            </el-table-column>
                            <el-table-column prop="phone" label="手机号" width="150">
                            </el-table-column>
                            <el-table-column prop="hiredate" label="入职时间" width="180">
                            </el-table-column>
                            <el-table-column prop="theirWork" label="所属职场">
                            </el-table-column>
                            <el-table-column fixed="right" label="操作" width="120">
                                <template slot-scope="scope">
                                    <permission permission-key="orgUser:editOrgUser">
                                        <router-link :to="{path: '/system/org/edit', query: {userid: scope.row.id,code: currentData.deptCode,source:currentData.sourceType || 1}}">修改</router-link>
                                    </permission>
                                    <permission permission-key="orgUser:delOrgUser">
                                        <a class="delete" @click="showDeleteLayer(scope.row.id)">删除</a>
                                    </permission>
                                </template>
                            </el-table-column>
                        </el-table>
                        <el-pagination v-if="tableData.total" :current-page="tableData.index" :page-sizes="[tableData.sizes,tableData.sizes*2, tableData.sizes*3, tableData.sizes*4]"
                            :page-size="tableData.size" :total="tableData.total" layout="total, sizes, prev, pager, next, jumper"
                            @size-change="tableSizeChange" @current-change="getTableData">
                        </el-pagination>
                    </div>
                </div>
            </div>
        </div>
        <!-- 编辑layer -->
        <layer :data="editLayerData" @on-cancel="closeEditLayer" @on-ok="editLayerConfirm">
            <div class="el-form">
                <div class="el-form-item is-required" :class="{'is-error':editLayerData.error}">
                    <label class="el-form-item__label" style="width: 100px;">公司名称</label>
                    <div class="el-form-item__content" style="margin-left: 112px;">
                        <div class="el-input">
                            <input autocomplete="off" type="text" validateevent="true" class="el-input__inner" placeholder="请输入公司名称" v-model="editLayerData.name"
                                @blur="layerInputBlur">
                        </div>
                        <div class="el-form-item__error" v-if="editLayerData.error">请输入公司名称</div>
                    </div>
                </div>
            </div>
        </layer>
        <!-- 删除layer  -->
        <layer :data="deleteLayerData" @on-ok="deleteLayerConfirm"></layer>
    </div>
</template>
<script>
    import './org.less'
    import orgManage from '@/mixins/orgManage'
    export default {
        name: 'org',
        mixins: [orgManage],
        data() {
            return {
            }
        },
        computed: {
            deptCode() {
                return this.$route.query.code || 0
            }
        },
        mounted() {
            this.$store.dispatch('setBreadData', [
                {
                    name: '系统管理'
                },
                {
                    name: '组织架构管理'
                }
            ])
        },
        methods: {
        },
        watch: {
            deptCode(val) {
                this.getTableData(1)
            }
        }
    }
</script>